// 引入 request 方法，假设 request 方法已经定义在某个工具文件中
import request from '/@/utils/request';
import {
    AddCodeGenInput,
    DeleteCodeGenInput,
    UpdateCodeGenInput,
    CodeGenInput,
    SysCodeGen,
} from '../models';
// 定义 API 路径枚举
enum Api {
    SysCodeGenAdd = '/sysCodeGen/add',
    SysCodeGenApplicationNamespaces = '/sysCodeGen/applicationNamespaces',
    SysCodeGenColumnListByTableName = '/sysCodeGen/columnListByTableName/{tableName}/{configId}',
    SysCodeGenDatabaseList = '/sysCodeGen/databaseList',
    SysCodeGenDelete = '/sysCodeGen/delete',
    SysCodeGenDetail = '/sysCodeGen/detail',
    SysCodeGenPage = '/sysCodeGen/page',
    SysCodeGenPreview = '/sysCodeGen/preview',
    SysCodeGenRunLocal = '/sysCodeGen/runLocal',
    SysCodeGenTableList = '/sysCodeGen/tableList/{configId}',
    SysCodeGenUpdate = '/sysCodeGen/update',
}

// 定义 API 方法
/**
 * 增加代码生成 🔖
 * @param body 请求体
 */
export const apiSysCodeGenAddPost = (body?: AddCodeGenInput) =>
    request({
        url: Api.SysCodeGenAdd,
        method: 'post',
        data: body,
    });

/**
 * 获取程序保存位置 🔖
 */
export const apiSysCodeGenApplicationNamespacesGet = () =>
    request({
        url: Api.SysCodeGenApplicationNamespaces,
        method: 'get',
    });

/**
 * 根据表名获取列集合 🔖
 * @param tableName 表名
 * @param configId 配置Id
 */
export const apiSysCodeGenColumnListByTableNameTableNameConfigIdGet = (tableName: string, configId: string) =>
    request({
        url: Api.SysCodeGenColumnListByTableName
            .replace('{tableName}', encodeURIComponent(tableName))
            .replace('{configId}', encodeURIComponent(configId)),
        method: 'get',
    });

/**
 * 获取数据库库集合 🔖
 */
export const apiSysCodeGenDatabaseListGet = () =>
    request({
        url: Api.SysCodeGenDatabaseList,
        method: 'get',
    });

/**
 * 删除代码生成 🔖
 * @param body 请求体
 */
export const apiSysCodeGenDeletePost = (body?: Array<DeleteCodeGenInput>) =>
    request({
        url: Api.SysCodeGenDelete,
        method: 'post',
        data: body,
    });

/**
 * 获取代码生成详情 🔖
 * @param id 代码生成器Id
 */
export const apiSysCodeGenDetailGet = (id: number) =>
    request({
        url: Api.SysCodeGenDetail,
        method: 'get',
        params: { Id: id },
    });

/**
 * 获取代码生成分页列表 🔖
 * @param body 请求体
 */
export const apiSysCodeGenPagePost = (body?: CodeGenInput) =>
    request({
        url: Api.SysCodeGenPage,
        method: 'post',
        data: body,
    });

/**
 * 获取代码生成预览 🔖
 * @param body 请求体
 */
export const apiSysCodeGenPreviewPost = (body?: SysCodeGen) =>
    request({
        url: Api.SysCodeGenPreview,
        method: 'post',
        data: body,
    });

/**
 * 代码生成到本地 🔖
 * @param body 请求体
 */
export const apiSysCodeGenRunLocalPost = (body?: SysCodeGen) =>
    request({
        url: Api.SysCodeGenRunLocal,
        method: 'post',
        data: body,
    });

/**
 * 获取数据库表(实体)集合 🔖
 * @param configId 配置Id
 */
export const apiSysCodeGenTableListConfigIdGet = (configId: string) =>
    request({
        url: Api.SysCodeGenTableList.replace('{configId}', encodeURIComponent(configId)),
        method: 'get',
    });

/**
 * 更新代码生成 🔖
 * @param body 请求体
 */
export const apiSysCodeGenUpdatePost = (body?: UpdateCodeGenInput) =>
    request({
        url: Api.SysCodeGenUpdate,
        method: 'post',
        data: body,
    });